import { request } from "../../utils/request.js";
import regeneratorRuntime from "../../utils/runtime.js";
var bsurl = require('../../utils/bsurl.js');
Page({
  data: {
    hotComments:[],
    hotTime:[],
    newcomments:[],
    newTime:[]
  },
  async getMusicDiscussInfo(Id,way){
    if(way==1){
      let discussInfo=await request({url: bsurl+'comment/music?id='+Id});
      this.hanlediscussInfo(discussInfo)
    }else{
      let discussInfo=await request({url: bsurl+'comment/playlist?id='+Id});
      this.hanlediscussInfo(discussInfo)
    }  
  },
  hanlediscussInfo(discussInfo){
    let hotComments=discussInfo.hotComments.map(v=>{
      return{
        nickname:v.user.nickname,
        avatarUrl:v.user.avatarUrl,
        content:v.content,
        likedCount:v.likedCount
      }
    })
    let newcomments=discussInfo.hotComments.map(v=>{
      return{
        nickname:v.user.nickname,
        avatarUrl:v.user.avatarUrl,
        content:v.content,
        likedCount:v.likedCount
      }
    })
    let hotTime=discussInfo.hotComments.map(v=>this.formatDate(v.time))
    let newTime=discussInfo.comments.map(v=>this.formatDate(v.time))
    this.setData({
      hotComments,
      newcomments,
      hotTime,
      newTime
    })
  },
  formatDate(now){
    var Noday=new Date(now);
    var year=Noday.getFullYear();  
    var month=Noday.getMonth()+1;  
    var date=Noday.getDate();      
    let time=year+"年"+month+"月"+date+"日"
    return time;
  },
  onLoad: function (options) {
    const playingId=options.playingId;
    const playlistId=options.playlistId;
    if(playingId){
      this.getMusicDiscussInfo(playingId,1);
    }else{
      this.getMusicDiscussInfo(playlistId,2);
    }
  },
})